<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<title>打开关闭窗口</title>
	</head>

	<body>
		<br />
		<input type="button" value="打开" onclick="openwin()" />
		<br />
		<br />
		<input type="button" value="关闭" onclick="closewin()" />
		<br />
		<br />
		<input type="button" value="检测窗口是否关闭" onclick="checkwin()" />
		<p id="msg"></p>
		<script>
			var win;
			//打开窗口：定义窗口名称。窗口大小、位置
			function openwin() {
				win = window.open('', '我的新窗口', 'width=400,height=200,left=200,top=100');
				//在窗口最中写入内容
				win.document.write(win.name + '<br>');
				win.document.write(win.parent);
			}

			function closewin() {
				if(win) {
					win.close();
				} else {
					alter("没有新的窗口打开")
				}
			}
			//检测窗口是否关闭
			function checkwin() {
				var s;
				if(win) { //窗口没有被打开，判断窗口是否关闭
					s = (win.closed ? '窗口已关闭' : '窗口打开着 还未关闭');

				} else {
					s = "窗口没有被打开";
				}
				var msg = document.getElementById('msg');
				msg.innerHTML = s;
			}
		</script>
	</body>

</html>